package com.mobile.common.base.support;

import java.util.Collections;
import java.util.List;

public class Page<T> {

	public Page() {
		this.pageNo = 1;
		this.pageSize = 10;
		this.totalSize = -1L;
		this.result = Collections.emptyList();
	}
	
	public Page(int pageSize) {
		this.pageNo = 1;
		this.pageSize = pageSize;
		this.totalSize = -1L;
		this.result = Collections.emptyList();
	}

	/**当前页号*/
	private int pageNo;
	/**每页记录数*/
	private int pageSize;
	/**总记录数*/
	private Long totalSize;
	/**结果集*/
	private List<T> result;
	/**总页数*/
	private int totalPage;
	
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
		if (pageNo < 1)
			this.pageNo = 1;
		if (pageNo > getTotalPage() && getTotalPage() != 0)
			this.pageNo = getTotalPage();
	}
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		if (pageSize < 1)
			this.pageSize = 1;
	}
	public Long getTotalSize() {
		return totalSize;
	}
	public void setTotalSize(Long totalSize) {
		this.totalSize = totalSize;
	}
	public List<T> getResult() {
		return result;
	}
	public void setResult(List<T> result) {
		this.result = result;
	}
	/**每页起始index*/
	public int getBeginIndex() {
		return (pageNo - 1) * pageSize;
	}

	public int getTotalPage() {
		if(totalSize%pageSize==0)
			totalPage = Integer.parseInt(String.valueOf(totalSize))/pageSize;
		else
			totalPage = Integer.parseInt(String.valueOf(totalSize))/pageSize+1;
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
}
